<template>
	<view class="apply">
		<view v-if="applyList.length === 0" class="no-data">暂时没有报名信息呢~</view>
		<view v-for="item in applyList" :key="item.id">
			<view class="time">{{item.createTime}}</view>
			<uni-card
			  v-if="!item.address"
			  :title="item.activityName"
			  mode="style"
			  :is-shadow="true"
			  :thumbnail="item.photo"
			  note="点击查看详情"
			  @click="handleClick(item)"
			>
			  <view class="detail">
			  	<view class="name">姓名</view>
			  	<view class="content">{{item.username}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">电话号码</view>
			  	<view class="content">{{item.mobile}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">百度账号</view>
			  	<view class="content">{{item.baiduName}}</view>
			  </view>
			</uni-card>
			<uni-card
			  v-if="item.address"
			  title="新店入驻报名"
			  mode="style"
			  :is-shadow="true"
			  :thumbnail="require('@/static/newshop.jpg')"
			  note="点击查看详情"
			  @click="handleClick(item)"
			>
			  <view class="detail">
			  	<view class="name">姓名</view>
			  	<view class="content">{{item.username}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">电话号码</view>
			  	<view class="content">{{item.telephone}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">微信号</view>
			  	<view class="content">{{item.wechat}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">学校</view>
			  	<view class="content">{{item.school_name}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">店铺名称</view>
			  	<view class="content">{{item.shopName}}</view>
			  </view>
			  <view class="detail">
			  	<view class="name">店铺地址</view>
			  	<view class="content">{{item.address}}</view>
			  </view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import {uniCard} from '@dcloudio/uni-ui'
	import {getApplyList} from '@/api/activity.js'
	import {getStoreEnrollByUserId} from '@/api/shop.js'
	import {mapState} from 'vuex'
	export default{
		components: {uniCard},
		computed: {
		  ...mapState(['userInfo'])
		},
		data(){
			return{
				applyList: []
			}
		},
		onLoad(){
			this.getApplyList()
		},
		methods:{
			handleClick(item){
				if(item.address){  // 店铺入驻的报名
					uni.navigateTo({
						url: '/pages/mine/application/shop-apply-detail',
						success: (res)=>{
						    // 通过eventChannel向被打开页面传送数据
						    res.eventChannel.emit('acceptDataFromOpenerPage', item)
						}
					})
				}else{  // 校园大使的报名
					uni.navigateTo({
						url: '/pages/mine/application/school-detail',
						success: (res)=>{
						    // 通过eventChannel向被打开页面传送数据
						    res.eventChannel.emit('acceptDataFromOpenerPage', item)
						}
					})
				}
			},
			getApplyList(){
				getApplyList({userId: this.userInfo.id}).then(res=>{
					if(res.code === 200){
						console.log(res)
						this.applyList = this.applyList.concat(res.data)
					}
				})
				getStoreEnrollByUserId(this.userInfo.id).then(res=>{
					if(res.code === 200){
						console.log(res)
						this.applyList = this.applyList.concat(res.data)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.apply{
		margin-top: 30rpx;
		.no-data{
			text-align: center;
		}
		.time{
			text-align: center;
		}
		.detail{
			display: flex;
			flex-wrap: wrap;
			.name{
				width: 140rpx;
				margin-right: 20rpx;
				color: #666666
			}
			.content{
				width: 400rpx;
			}
		}
	}
</style>
